package entry;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/useCookie")
public class RunCookie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //这里处理get请求相关内容
        //设置cookie

        //先设置个公共的内容吧，不然写起来太麻烦了
        //写不上去，，服了，，
        String curOrigin = req.getHeader("Origin");
        resp.setHeader("Access-Control-Allow-Origin", curOrigin);
        resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");

        //在这个地方设置cookie
//        resp.addCookie(new Cookie("111","222"));
//        resp.setHeader("Set-Cookie","xxx=aaa;");
        //哪个弱智会这么写呢？前端页面肯定是写在前端啊
        HttpSession session=req.getSession();
        session.setAttribute("mobile","22222");

        resp.getWriter().println(session.getAttribute("mobile"));
    }
}
